package com.temp.check;

import com.temp.check.base.DBCond;
import com.temp.check.base.DBConfig;
import com.temp.check.base.DBColumnVO;
import com.temp.check.base.DBUtil;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 博瑞达修改仓库，库区编码
 */
public class BrdAreaChangeAction {

    public static void main(String[] args) {
        try {
            DBConfig config = DBUtil.getConfig("192.168.30.201:28995", "root", "qp*imsp666");
            //查询所有数据列
            Map<String, String> map = new LinkedHashMap<>();
            map.put("SCXB", "501");
            //1
            DBCond cond1 = new DBCond().setDbLike("imsp_order_").setColumnLikes("warehouse_code", "area_code");
            printSql(DBUtil.queryColumn(config, cond1), map);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }


    private static void printSql(List<DBColumnVO> dataColumnVOS, Map<String, String> map) {
        List<String> noTenantList = new ArrayList<>();
        noTenantList.add("stock_summary_detail");
        noTenantList.add("spare_store_house");
        noTenantList.add("spare_inventory_list");
        StringBuilder upt = new StringBuilder();
        for (DBColumnVO d : dataColumnVOS) {
            upt.append("\n");
            for (Map.Entry<String, String> entry : map.entrySet()) {
                upt.append("\n");
                upt.append(" update ").append(d.getDbName()).append(".").append(d.getTableName());
                upt.append(" set ").append(d.getColumnName()).append("='").append(entry.getValue()).append("'");
                upt.append(" where ").append(d.getColumnName()).append("='").append(entry.getKey()).append("' ");
                if (noTenantList.contains(d.getTableName())) {
                    upt.append("; ");
                } else {
                    upt.append(" and tenant_id = '666666' ; ");
                }

            }

        }

        upt.append("\n");
        System.out.println(upt.toString());
    }

}